﻿using FighttheLandOwner.GameCore;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace FighttheLandOwner.UI
{
    class CardPainter
    {
        /// <summary>
        /// 绘制单张牌
        /// </summary>
        /// <param name="card"></param>
        /// <param name="position"></param>
        /// <param name="g"></param>
        private static void ShowCard(Card card, Point position, Graphics g)
        {
            var resourcepath = @"resource\cards\";
            Image image = Image.FromFile(string.Format(resourcepath + @"{0}\{1}.jpg",
                Card.GetAttributeValue(card.Type),
                Card.GetAttributeValue(card.Value)));
            g.DrawImage(image, position);
            image.Dispose();
        }

        /// <summary>
        /// 绘制别人的牌的背面
        /// </summary>
        /// <param name="num"></param>
        /// <param name="firstposition"></param>
        /// <param name="g"></param>
        public static void ShowCardBack(int num, Point firstposition, Graphics g)
        {
            int offset = 12;
            Image image = Image.FromFile(@"resource\cards\back.jpg");
            for (var i = 0; i < num; i++)
            {
                g.DrawImage(image, firstposition.X, firstposition.Y + offset * i);
            }
            image.Dispose();
        }

        /// <summary>
        /// 绘制一个牌堆
        /// </summary>
        /// <param name="cards"></param>
        /// <param name="firstposition"></param>
        /// <param name="g"></param>
        public static void ShowCards(List<Card> cards, Point firstposition, Graphics g)
        {
            int offset = 25;
            foreach (var card in cards)
            {
                ShowCard(card, firstposition, g);
                firstposition.X += offset;
            }
        }

        

        public static void ShowCards(List<Card> cards, Point firstposition, Graphics g,int offset)
        {
            foreach (var card in cards)
            {
                ShowCard(card, firstposition, g);
                firstposition.X += offset;
            }
        }
    }
}
